<template>
    <div class="identify">
    <el-card class="ConsumptionCard">
      <span>请输入检测期内的用电量数据：</span>
      <br>
      <span> 单位（Wh）</span>
    <el-form  :model="ConsumptionForm" :rules="Crules"  ref="ConsumptionForm">
          <el-form-item prop="pre5">
            <el-input placeholder="窗口期前五天用电量" size="medium" class="input"  v-model="ConsumptionForm.pre5" ></el-input>
          </el-form-item>
          <el-form-item prop="pre4">
            <el-input placeholder="窗口期前四天用电量" size="medium" class="input"  v-model="ConsumptionForm.pre4" ></el-input>
          </el-form-item>
           <el-form-item prop="pre3">
            <el-input placeholder="窗口期前三天用电量" size="medium" class="input"  v-model="ConsumptionForm.pre3" ></el-input>
          </el-form-item>
          <el-form-item prop="pre2">
            <el-input placeholder="窗口期前两天用电量" size="medium" class="input"  v-model="ConsumptionForm.pre2" ></el-input>
          </el-form-item>
          <el-form-item prop="pre1">
            <el-input placeholder="窗口期前一天用电量" size="medium" class="input"  v-model="ConsumptionForm.pre1" ></el-input>
          </el-form-item>
          <el-form-item prop="oneC">
            <el-input placeholder="第一天用电量" size="medium" class="input"  v-model="ConsumptionForm.oneC" ></el-input>
          </el-form-item>
          <el-form-item prop="twoC">
            <el-input placeholder="第二天用电量" size="medium" class="input"  v-model="ConsumptionForm.twoC" ></el-input>
          </el-form-item>
          <el-form-item prop="threeC">
            <el-input placeholder="第三天用电量" size="medium" class="input"  v-model="ConsumptionForm.threeC"></el-input>
          </el-form-item>
          <el-form-item prop="fourC">
            <el-input placeholder="第四天用电量" size="medium" class="input"  v-model="ConsumptionForm.fourC"></el-input>
          </el-form-item>
          <el-form-item prop="fiveC">
            <el-input placeholder="第五天用电量" size="medium" class="input"  v-model="ConsumptionForm.fiveC"></el-input>
          </el-form-item>
          <el-form-item prop="sixC">
            <el-input placeholder="第六天用电量" size="medium" class="input"  v-model="ConsumptionForm.sixC"></el-input>
          </el-form-item>
          <el-form-item prop="sevenC">
            <el-input placeholder="第七天用电量" size="medium" class="input"  v-model="ConsumptionForm.sevenC"></el-input>
          </el-form-item>
          <el-form-item prop="eightC">
            <el-input placeholder="第八天用电量" size="medium" class="input"  v-model="ConsumptionForm.eightC"></el-input>
          </el-form-item>
          <el-form-item prop="nineC">
            <el-input placeholder="第九天用电量" size="medium" class="input"  v-model="ConsumptionForm.nineC"></el-input>
          </el-form-item>
          <el-form-item prop="tenC">
            <el-input placeholder="第十天用电量" size="medium" class="input"  v-model="ConsumptionForm.tenC"></el-input>
          </el-form-item>
          <el-form-item prop="elevenC">
            <el-input placeholder="第十一天用电量" size="medium" class="input"  v-model="ConsumptionForm.elevenC"></el-input>
          </el-form-item>
          <el-form-item prop="aft1">
            <el-input placeholder="窗口期后一天用电量" size="medium" class="input"  v-model="ConsumptionForm.aft1" ></el-input>
          </el-form-item>
          <el-form-item prop="aft2">
            <el-input placeholder="窗口期后两天用电量" size="medium" class="input"  v-model="ConsumptionForm.aft2" ></el-input>
          </el-form-item>
          <el-form-item prop="aft3">
            <el-input placeholder="窗口期后三天用电量" size="medium" class="input"  v-model="ConsumptionForm.aft3" ></el-input>
          </el-form-item>
          <el-form-item prop="aft4">
            <el-input placeholder="窗口期后四天用电量" size="medium" class="input"  v-model="ConsumptionForm.aft4" ></el-input>
          </el-form-item>
          <el-form-item prop="aft5">
            <el-input placeholder="窗口期后五天用电量" size="medium" class="input"  v-model="ConsumptionForm.aft5" ></el-input>
          </el-form-item>
    </el-form>
    <div class="ConsumptionFoot">
        <el-button class="btn" type="primary" size="medium" @click="calculate1">处理</el-button>
    </div>
    </el-card>
    
    <el-card class="LineCard">
      <span>请输入检测期内的线路相关电量数据：</span>
      <br>
      <span> 单位（kWh）</span>
    <el-form class="lineloss1" :model="lineloss1" :rules="Lrules1"  ref="lineloss1">
          <el-form-item prop="oneL">
            <el-input placeholder="第一天线路供电量" size="medium" class="input"  v-model="lineloss1.oneL" ></el-input>
          </el-form-item>
          <el-form-item prop="twoL">
            <el-input placeholder="第二天线路供电量" size="medium" class="input"  v-model="lineloss1.twoL" ></el-input>
          </el-form-item>
          <el-form-item prop="threeL">
            <el-input placeholder="第三天线路供电量" size="medium" class="input"  v-model="lineloss1.threeL"></el-input>
          </el-form-item>
          <el-form-item prop="fourL">
            <el-input placeholder="第四天线路供电量" size="medium" class="input"  v-model="lineloss1.fourL"></el-input>
          </el-form-item>
          <el-form-item prop="fiveL">
            <el-input placeholder="第五天线路供电量" size="medium" class="input"  v-model="lineloss1.fiveL"></el-input>
          </el-form-item>
          <el-form-item prop="sixL">
            <el-input placeholder="第六天线路供电量" size="medium" class="input"  v-model="lineloss1.sixL"></el-input>
          </el-form-item>
          <el-form-item prop="sevenL">
            <el-input placeholder="第七天线路供电量" size="medium" class="input"  v-model="lineloss1.sevenL"></el-input>
          </el-form-item>
          <el-form-item prop="eightL">
            <el-input placeholder="第八天线路供电量" size="medium" class="input"  v-model="lineloss1.eightL"></el-input>
          </el-form-item>
          <el-form-item prop="nineL">
            <el-input placeholder="第九天线路供电量" size="medium" class="input"  v-model="lineloss1.nineL"></el-input>
          </el-form-item>
          <el-form-item prop="tenL">
            <el-input placeholder="第十天线路供电量" size="medium" class="input"  v-model="lineloss1.tenL"></el-input>
          </el-form-item>
          <el-form-item prop="elevenL">
            <el-input placeholder="第十一天线路供电量" size="medium" class="input"  v-model="lineloss1.elevenL"></el-input>
          </el-form-item>
    </el-form>
    <el-form  class="lineloss2" :model="lineloss2" :rules="Lrules2"  ref="lineloss2">
          <el-form-item prop="oneY">
            <el-input placeholder="第一天线路用电量" size="medium" class="input"  v-model="lineloss2.oneY" ></el-input>
          </el-form-item>
          <el-form-item prop="twoY">
            <el-input placeholder="第二天线路用电量" size="medium" class="input"  v-model="lineloss2.twoY" ></el-input>
          </el-form-item>
          <el-form-item prop="threeY">
            <el-input placeholder="第三天线路用电量" size="medium" class="input"  v-model="lineloss2.threeY"></el-input>
          </el-form-item>
          <el-form-item prop="fourY">
            <el-input placeholder="第四天线路用电量" size="medium" class="input"  v-model="lineloss2.fourY"></el-input>
          </el-form-item>
          <el-form-item prop="fiveY">
            <el-input placeholder="第五天线路用电量" size="medium" class="input"  v-model="lineloss2.fiveY"></el-input>
          </el-form-item>
          <el-form-item prop="sixY">
            <el-input placeholder="第六天线路用电量" size="medium" class="input"  v-model="lineloss2.sixY"></el-input>
          </el-form-item>
          <el-form-item prop="sevenY">
            <el-input placeholder="第七天线路用电量" size="medium" class="input"  v-model="lineloss2.sevenY"></el-input>
          </el-form-item>
          <el-form-item prop="eightY">
            <el-input placeholder="第八天线路用电量" size="medium" class="input"  v-model="lineloss2.eightY"></el-input>
          </el-form-item>
          <el-form-item prop="nineY">
            <el-input placeholder="第九天线路用电量" size="medium" class="input"  v-model="lineloss2.nineY"></el-input>
          </el-form-item>
          <el-form-item prop="tenY">
            <el-input placeholder="第十天线路用电量" size="medium" class="input"  v-model="lineloss2.tenY"></el-input>
          </el-form-item>
          <el-form-item prop="elevenY">
            <el-input placeholder="第十一天线路用电量" size="medium" class="input"  v-model="lineloss2.elevenY"></el-input>
          </el-form-item>
    </el-form>
      <div class="linelossFoot">
        <el-button class="btn" type="primary" size="medium" @click="calculate2">处理</el-button>
      </div>
    </el-card>

    <el-card class="warnCard">
      <span>请确定检测期内的终端报警：</span>
    <div class="checkbox-group">
    <el-checkbox class="checked1" v-model="checked1" label="电压缺相告警"></el-checkbox>
    <el-checkbox class="checked2" v-model="checked2" label="电压断相告警"></el-checkbox>
    <el-checkbox class="checked3" v-model="checked3" label="电流反极性告警"></el-checkbox>
    <el-checkbox class="checked4" v-model="checked4" label="电流过负荷告警"></el-checkbox>
    <el-checkbox class="checked5" v-model="checked5" label="电压过高告警"></el-checkbox>
    <el-checkbox class="checked6" v-model="checked6" label="电压过低告警"></el-checkbox>
      <div class="warnFoot">
        <el-button class="btn" type="primary" size="medium" @click="calculate3">处理</el-button>
      </div>
    </div>
    </el-card>

    <el-card class="IdentifyCard">
      <span class="">请输入要检测的用户编号：</span>
      <el-input placeholder="用户编号" size="medium" class="inputUserID"  v-model="UserID"></el-input>
      <span class="Window">请输入要检测的窗口期：</span>
      <span class="StartDate">起始日期</span>
      <span class="EndDate">结束日期</span>
    <div class="Date">
     <el-date-picker
      v-model="Sdate"
      type="date"
      placeholder="选择起始日期">
     </el-date-picker>
    </div>
    <span class="EDate">{{ endDate }}</span>
    <!-- 使用计算属性里面的变量来显示十一天之后的日期 -->
      <span class="Identify1">处理得到的电量下降趋势指标为：{{ ResultForm.electricity }}</span>
      <span class="Identify2">处理得到的线损指标为：{{ ResultForm.lineloss }}</span>
      <span class="Identify3">处理得到的告警类指标为：{{ ResultForm.warn }}</span>
      <span class="Result">窃漏电识别结果为：{{ Result }}</span>
      <div class="IdentifyFoot">
        <el-button class="btn" type="primary" size="medium" @click="identify">识别</el-button>
      </div>
    </el-card>

      </div>
  </template>
  
  <script>
import { Result } from 'element-ui';

  
  export default {
    data () {
    const checkElectricity=(rule, value, callback) =>{
    const reg = /^[0-9]*\.?[0-9]+$/; // 匹配浮点数
    if (!reg.test(value)) {
      callback(new Error('请输入符合格式的用电量，如6.6'));
    } else {
      callback();
    }
  }
    return {
      checked1:false,
      checked2:false,
      checked3:false,
      checked4:false,
      checked5:false,
      checked6:false,
      ResultForm:{//指标表单，计算出三个指标之后把该表单提交到后端请求机器学习模型调用服务
      electricity:'',//计算出的电量下降趋势指标
      lineloss:'',//线损指标
      warn:''//告警类指标
      },
      Result:'',//识别结果
      UserID:'',//检测的用户编号
      Sdate:'',//检测的窗口期初始日期
      Edate:'',//检测的结束日期
      ConsumptionForm:{//用户在十一天窗口期内的每天用电量输入表单绑定的数据模型对象
        pre5:'6200',
        pre4:'6000',
        pre3:'6100',
        pre2:'6160',
        pre1:'5900',
        oneC:'5990',
        twoC: '6000',
        threeC: '6100',
        fourC:'6050',
        fiveC:'5950',
        sixC:'5900',
        sevenC:'5800',
        eightC:'6101',
        nineC:'6020',
        tenC:'5992',
        elevenC:'6000',
        aft1:'6200',
        aft2:'5909',
        aft3:'6040',
        aft4:'5920',
        aft5:'5833',
      },
      lineloss1:{//用户在十一天窗口期内的每天线路供电量输入表单绑定的数据模型对象
        oneL:'600',
        twoL: '622',
        threeL: '562',
        fourL:'603',
        fiveL:'630',
        sixL:'610',
        sevenL:'605',
        eightL:'623',
        nineL:'633',
        tenL:'642',
        elevenL:'637',
      },
      lineloss2:{//用户在十一天窗口期内的每天线路用电量输入表单绑定的数据模型对象
        oneY:'600',
        twoY: '622',
        threeY: '560',
        fourY:'600',
        fiveY:'621',
        sixY:'600',
        sevenY:'590',
        eightY:'621',
        nineY:'630',
        tenY:'640',
        elevenY:'635',
      },
      Crules: {//窗口期内的用电量输入表单的公共校验规则
        pre5: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        pre4: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        pre3: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        pre2: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        pre1: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        oneC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity }, 
    //在这个用电量表单校验规则中对每个字段属性都添加一个自定义校验，在自定义校验中使用正则表达式验证输入数据是否是浮点数，触发提醒msg规则同样是
    //失去焦点或者对表单使用validate方法校验时
        ],
        twoC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        threeC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        fourC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        fiveC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        sixC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        sevenC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        eightC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        nineC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        tenC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        elevenC: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        aft1: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        aft2: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        aft3: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        aft4: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
        aft5: [
          { required: true, message: '请输入正确用电量', trigger: 'blur',validator: checkElectricity },
        ],
      },
      Lrules1: {//窗口期内的线路供电量输入表单的公共校验规则
        oneL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity }, 
        ],
        twoL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
        threeL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
        fourL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
        fiveL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
        sixL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
        sevenL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
        eightL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
        nineL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
        tenL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
        elevenL: [
          { required: true, message: '请输入正确线路供电量', trigger: 'blur',validator: checkElectricity },
        ],
      },
      Lrules2: {//窗口期内的线路供电量输入表单的公共校验规则
        oneY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity }, 
        ],
        twoY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
        threeY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
        fourY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
        fiveY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
        sixY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
        sevenY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
        eightY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
        nineY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
        tenY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
        elevenY: [
          { required: true, message: '请输入正确线路用电量', trigger: 'blur',validator: checkElectricity },
        ],
      },
    }
  },

  computed: {
  endDate() {//将起始日期之后的第十一天作为一个计算属性（本质上是一个函数）来动态显示
    if (this.Sdate) {
      // 使用 Date 对象计算出从起始日期开始的第11天
      const startDate = new Date(this.Sdate)
      startDate.setDate(startDate.getDate() + 10)

      // 获取年、月、日并拼接成所需的格式
      const year = startDate.getFullYear()
      const month = startDate.getMonth() + 1
      const day = startDate.getDate()
      this.Edate=`${year}-${month}-${day}`
      return `${year}-${month}-${day}`
    }
    return null
  },
  StartDate(){//起始日期使用计算属性作格式转换
    if (this.Sdate) {
      const startDate = new Date(this.Sdate)
      startDate.setDate(startDate.getDate() + 0)
      // 获取年、月、日并拼接成所需的格式
      const year = startDate.getFullYear()
      const month = startDate.getMonth() + 1
      const day = startDate.getDate()
      return `${year}-${month}-${day}`
    }
    return null
  },
  requestBody() {//识别记录的新增数据体,取各个零散的属性
      return {
        userid: this.UserID,
        startdate: this.StartDate,
        enddate: this.endDate,
        electricity: this.ResultForm.electricity,
        lineloss: this.ResultForm.lineloss,
        warn: this.ResultForm.warn,
        result: this.Result,
      };
    }
},

  methods:{
    calculate1(){//把表单接收的窗口期内的用电量数据通过数学公式计算出电量下降趋势指标
      this.$refs['ConsumptionForm'].validate((valid) => {//先对表单数据校验
        if (valid) {
          //表单校验合法
      const consumptionArray = Object.values(this.ConsumptionForm);//先把用电量数据模型对象转化成一个数组
      var i,j,x=0;
      var K = new Array(11);//数组K用来存储11天每天的电量趋势
      var Numerator,Denominator;//Ki的分子和分母
      for (i = 5; i < 16; i++) {//遍历每一天，计算出每天的电量趋势Ki,从第六天开始是窗口期第一天
        Numerator=0;
        Denominator=0;
        var start,end;//先确定窗口期前后边界，
        start=i-5;
        end=i+5;
        //到此确定了第i天窗口期的起点和终点，然后分子分母是对应的式子从起点累加到终点
        var f,l,sum=0;//先计算起点到终点平均用电量f和平均天序号l
        for (j =start; j <=end; j++) {
	       sum+=parseFloat(consumptionArray[j]);//把用电量进行累加
        }
      
        f=sum/(end-start+1);
       
        var n=end-start+1;
        l=((n+1)*n/2)/(end-start+1);//先计算起点到终点期间天序号平均值l和用电量平均值f
      
        for (j = start; j <=end; j++){
	       Numerator+=parseFloat((consumptionArray[j]-f)*(j+1-l));//天序号是下标加1
        }
     
        for (j = start; j <=end; j++){
	       Denominator+=parseFloat((j+1-l)*(j+1-l));//天序号是下标加1
        }
     
        K[x]=Numerator/Denominator;//得到分子分母之后相除即可得到第i天的电量趋势Ki
        x++;
               }
//得到十一天窗口期内每天的电量趋势之后，从第二天开始，检查每天的电量趋势Ki和前一天比是否下降了，是则累加1，否则累加0以此得到电量下降趋势指标
        var D=0;
        console.log("第0天用电量趋势是"+K[0])
        for (i = 1; i < 11; i++) {
          console.log("第"+i+"天用电量趋势是"+K[i])
        if(K[i]<0&&K[i-1]<0){//如果第i天和第i-1天电量趋势都是小于零（前后5天窗口期内用电量拟合的直线斜率都小于零）
          //则用电量是下降趋势，计数
          D+=1;
        }
        else if(K[i]>0&&K[i-1]>0){//如果两个斜率都大于0，则用电量是上升趋势，不计数
          D+=0;
        }
        else if(K[i]>0&&K[i-1]<0){ //i正i-1负则用电量趋势在上升
         D+=0;
        }
        else if(K[i]<0&&K[i-1]>0){ //i负i-1正则用电量趋势在下降
         D+=1;
        }
        else{ //其他情况不计数，比如斜率为0
         D+=0;
        }
    
        }
        this.ResultForm.electricity=D;
    }
  })
},
calculate2(){//把表单接收的窗口期内的线路供电量数据和用电量数据通过数学公式计算出线损指标
  this.$refs['lineloss1'].validate((valid) => {//线路供电量表单数据校验
        if (valid) {  //供电量表单校验合法
          this.$refs['lineloss2'].validate((valid) => {//供电量表单校验通过之后对用电量表单校验
        if (valid) {  //用电量表单校验也合法
          //两个表单都通过校验之后开始计算
          //先计算出每天的线损率，然后分别统计当天与前5天之间的线损率平均值V1和当天与后5天之间的线损率平均值V2，增长率超过百分之1则为1否则为0​ 
          const linelossArray1 = Object.values(this.lineloss1);
          const linelossArray2 = Object.values(this.lineloss2);//先把供电量数据和用电量数据对象转化成数组
          var E = new Array(11);//存储十一天线损率的数组
          //开始计算十一天每天线损率
          var i;
          for(i=0;i<11;i++)
          {
            console.log("第"+i+"天的供电量是"+linelossArray1[i])
            console.log("第"+i+"天的用电量是"+linelossArray2[i])
            E[i]=parseFloat(1-linelossArray2[i]/linelossArray1[i]);
            console.log("第"+i+"天的线损率是"+E[i])
          }
          var V1=0,V2=0;//当天与前5天之间的线损率平均值V1和当天与后5天之间的线损率平均值V2
          for(i=0;i<6;i++)
          {
            V1+=parseFloat(E[i]);
          }
          console.log("前五天的线损率总和是"+V1)
          V1=V1/6;
          for(i=5;i<11;i++)
          {
            V2+=parseFloat(E[i]);
          }
          console.log("后五天的线损率总和是"+V2)
          V2=V2/6;
          //根据线损率计算线损指标
          console.log("前五天的线损率均值是"+V1)
            console.log("后五天的线损率均值是"+V2)
            console.log((V1-V2)/V2)
          if(((V1-V2)/V2)>0.01){
          this.ResultForm.lineloss=1;
          }
          else{
          this.ResultForm.lineloss=0;
          }
        }
  })    
        }
  })
},
    calculate3(){
    this.ResultForm.warn=0;
    if(this.checked1==true){
         this.ResultForm.warn++;
              }
    if(this.checked2==true){
      this.ResultForm.warn++;
              }
    if(this.checked3==true){
      this.ResultForm.warn++;
              }
    if(this.checked4==true){
      this.ResultForm.warn++;
              }
    if(this.checked5==true){
      this.ResultForm.warn++;
              }
    if(this.checked6==true){
      this.ResultForm.warn++;
              }
    },
    identify(){
      //发送POST请求到后端进行窃漏电识别
      if(this.UserID==''||this.Sdate==''||this.ResultForm.electricity==''||this.ResultForm.warn==''){
        this.$message.error("请先输入完整数据！")
        console.log(this.UserID+this.Sdate+this.ResultForm.electricity+this.ResultForm.lineloss+this.ResultForm.warn)
      } 
      else{//如果输入了完整数据，先检测是否有权限
        var user=sessionStorage.getItem("user") ? JSON.parse(sessionStorage.getItem("user")) : {}//先获取登录之后后端返回的dto
        if(user.role=='管理员'||user.grantstatus=='已授权'){//如果是管理员或者是已授权的普通用户就有识别权限
       this.request.post("/predict/feature", this.ResultForm).then(res => {
               console.log(res)
               if(res.data==1||res.data==0){
               if(res.data==1)
              this.Result="存在窃漏电行为" //识别结果赋给占位符变量显示
              else
              this.Result="不存在窃漏电行为"
                     //识别成功的同时要进行新增操作，将识别的记录添加到识别记录表中
         this.request.post("/predict/add", this.requestBody).then(res => {
                if (res.data.code === '200') {
                    this.$message.success("识别成功")
                } else {
                    this.$message.error("识别失败")
                }
            })  
               }
               else{
               this.$message.error("识别失败")
               }
           })
          }
        else{//非管理员
          this.$message.error("无识别权限！")
        }
          }
    }
  }
}
  </script>
  <style lang="less" >
  .identify{
  position: relative;
  top:20px;
  height: 1500px;

  .ConsumptionCard{
     position: relative;
     top:30px;
     left: 50px;
     width: 300px;
     height: 1400px;
     .ConsumptionFoot{
      position: absolute;
      top:1350px;
      right: 20px;
     }
  }

  .LineCard{
    position: relative;
     top:-1370px;
     left: 400px;
     width: 530px;
     height: 780px;
     .lineloss1{
    position: absolute;
    top:65px;
    left: 20px;
    width: 200px;
    height: 1000px;
  }
    .lineloss2{
    position: absolute;
    top:65px;
    left: 300px;
    width: 200px;
    height: 1000px;
  }

  .linelossFoot{
    position: absolute;
    top:740px;
    right: 20px;
  }
  }

  .warnCard{
    position: relative;
     top:-2150px;
     left: 980px;
     width: 500px;
     height: 780px;
     .checked1 {
     position: absolute;
     top:70px;
     left: 100px;
          }
        .checked2 {
     position: absolute;
     top:170px;
     left: 100px;
          }
          .checked3 {
     position: absolute;
     top:270px;
     left: 100px;
          }
          .checked4 {
     position: absolute;
     top:370px;
     left: 100px;
          }
          .checked5 {
     position: absolute;
     top:470px;
     left: 100px;
          }
          .checked6 {
     position: absolute;
     top:570px;
     left: 100px;
          }
   .el-checkbox__label {
  font-size: 20px; /* 设置文字大小 */
  font-weight: bold; /* 设置文字加粗 */
  margin-right: 20px; /* 设置文字间距 */
        }
    .warnFoot{
      position: absolute;
      top:740px;
      right: 20px;
    }
  }

  .IdentifyCard{
    position: relative;
     top:-2070px;
     left: 500px;
     width: 800px;
     height: 500px;
     .inputUserID{
      width: 200px;
     }
     .Window{
      position: absolute;
      top:80px;
      left: 20px;
     }
     .StartDate{
      position: absolute;
      top: 80px;
      left: 320px;
     }
     .EndDate{
      position: absolute;
      top: 80px;
      left: 600px;
     }
     .EDate{
      position: absolute;
      top: 130px;
      left: 600px;
     }
     .Date{
     position: absolute; 
     top:120px;
     left: 250px;
     }
     .Identify1{
     position: absolute;
     top:200px;
     left: 100px;
     }
     .Identify2{
      position: absolute;
     top:280px;
     left: 100px;
     }
     .Identify3{
      position: absolute;
     top:360px;
     left: 100px;
     }
     .Result{
      position: absolute;
     top:450px;
     left: 100px;
     }
     .IdentifyFoot{
     position: absolute;
     top: 420px;
     right: 20px;
     }    
    }
  }
  </style>
  